<template>
  <div class="new-songs">
    <MusicNav/>
    <div class="songs-container">
      <div class="tabs">
        <span 
          v-for="tab in tabs" 
          :key="tab.key" 
          @click="currentTab = tab.key"
          :class="{ active: currentTab === tab.key }"
          class="tab-item"
        >
          {{ tab.name }}
        </span>
      </div>
      <div class="songs-grid">
        <div class="song-item" v-for="song in songs" :key="song.id">
          <div class="image-box">
              <img 
                :src="song.cover" 
                :alt="song.name"
              >
              <div class="play-icon">
                <i class="fas fa-play-circle"></i>
              </div>
          </div>
          <div class="song-info">
            <div class="song-name">{{ song.name }}</div>
            <div class="song-artist">{{ song.artist }}</div>
            <div class="song-date">{{ song.date }}</div>
          </div>
        </div>
      </div>
    </div>
    <FooterNotice/>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import MusicNav from '@/components/music-nav.vue'
import FooterNotice from '@/components/footer-notice.vue'

const currentTab = ref('内地')

const tabs = [
  { key: '内地', name: '内地' },
  { key: '港台', name: '港台' },
  { key: '欧美', name: '欧美' },
  { key: '韩国', name: '韩国' },
  { key: '日本', name: '日本' }
]

// 重构后的数据，按区域组织歌曲
const allSongs = {
  '内地': [
    {
      id: 1,
      name: '1981 为爱二',
      artist: '赵兆 / 郝可维',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000000i8e0Y4HN7VQ_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 2,
      name: '夏夜小院',
      artist:'欧豪',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M0000043FcFZ4WMsfB_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 3,
      name: '小丑',
      artist: '段奥娟',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000001BIKct01CBFP_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 4,
      name: '很清醒很庆幸',
      artist: '向思思',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000000zoo1Y0u1DRn_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 5,
      name: '缺口',
      artist: '赖仔Morris',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000001QwT1D2TGPMK_1.jpg?max_age=2592000',
      date: '2025-03-04'
    }
  ],
  '港台': [
    {
      id: 1,
      name: '匍匐',
      artist: 'LaDY',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000001mC9B023Cgkt_1.jpg?max_age=2592000',
      date: '2025-03-04'
    }
  ],
  '欧美': [
    {
      id: 1,
      name: 'Stable Luck',
      artist: 'Grimmmz',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000004a6UyT34AMeu_1.jpg?max_age=2592000',
      date: '2025-03-04'
    }
  ],
  '韩国': [
    {
      id: 1,
      name: '라이딩 인생 OST Part.1 (Riding Life OST Part.1)',
      artist: 'GUREUMY',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000000yUoB90q1IUU_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 2,
      name: '선의의 경쟁 OST Part 4',
      artist: 'tripleS',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000004W7C5u4OCpJN_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 3,
      name: 'Breath of Love',
      artist: 'Piago',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000003vAMKd1Q0EO4_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 4,
      name: '우편물 보관함 Episode. 13 (mail box Episode. 13)',
      artist: 'Letter flow',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000001fCWUT41xZP8_1.jpg?max_age=2592000',
      date: '2025-03-04'
    },
    {
      id: 5,
      name: '김재기 REMEMBRANCE Part 02 (KIM JAE KI REMEMBRANCE Part',
      artist: '尤美',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000004BR09r0fDBQL_1.jpg?max_age=2592000',
      date: '2025-03-04'
    }
  ],
  '日本': [
    {
      id: 1,
      name: 'おおえのたかゆきクリスマスソング (feat. 初音ミク)',
      artist: 'oe /初音未来',
      cover: 'https://y.qq.com/music/photo_new/T002R300x300M000004MoNd73ddgVW_1.jpg',
      date: '2025-03-04'
    }
  ]
}

// 使用计算属性根据当前选中的标签筛选歌曲
const songs = computed(() => {
  return allSongs[currentTab.value] || []
})
</script>

<style scoped>
.new-songs {
  width: 100%;
  padding-bottom: 180px; /* 为固定定位的 footer 预留空间 */
}

.songs-container {
  padding: 20px;
}

.songs-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  max-width: 1200px;
  margin: 10px auto;
}

.song-item {
  flex: 0 0 calc(20% - 16px); /* 20% width for 5 columns, accounting for gap */
  min-width: 200px; /* Minimum width for responsiveness */
}

.image-box {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  background: #f5f5f5;
  position: relative;
  cursor: pointer;
}

.image-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.image-box:hover img {
  transform: scale(1.1);
}

.play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.play-icon i {
  color: white;
  font-size: 24px;
}

.image-box:hover .play-icon {
  opacity: 1;
}

.song-info {
  padding: 8px 0;
}

.song-name {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-artist {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-date {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}

@media screen and (max-width: 1200px) {
  .song-item {
    flex: 0 0 calc(33.333% - 14px); /* 3 columns on smaller screens */
  }
}

@media screen and (max-width: 768px) {
  .song-item {
    flex: 0 0 calc(50% - 10px); /* 2 columns on even smaller screens */
  }
}

@media screen and (max-width: 480px) {
  .song-item {
    flex: 0 0 100%; /* 1 column on mobile */
  }
}

.tabs {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
  max-width: 1200px;
  margin: 0 auto;
}

.tab-item {
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 14px;
  transition: all 0.3s ease;
}

.tab-item:hover {
  color: #2d8cf0;
}

.tab-item.active {
  background-color: #2d8cf0;
  color: white;
}
</style>